package d6_set;

import java.util.Objects;

//方式一: 让自定义的类实现Comparable接口, 重写里面的compareTo方法来指定比较规则
public class Girl implements Comparable<Girl>{
    private String name;
    private char sex;
    private int age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Girl girl = (Girl) o;
        return sex == girl.sex && age == girl.age && Double.compare(girl.height, height) == 0 && Objects.equals(name, girl.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, sex, age, height);
    }

    private double height;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public Girl(String name, char sex, int age, double height) {
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.height = height;
    }

    public Girl() {
    }

    @Override
    public String toString() {
        return "Girl{" +
                "name='" + name + '\'' +
                ", sex=" + sex +
                ", age=" + age +
                ", height=" + height +
                '}' + "\n";
    }

//    @Override
//    public int compareTo(Girl o) {
//        return o.age - this.age;
//    }
    //想对重复的保留:
    @Override
    public int compareTo(Girl o) {
        return o.age - this.age >= 0 ? 1 : -1;
    }
}
